package com.pageselect.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pageselect.constant.HttpStatus;
import com.pageselect.dto.HjyCommunityDto;
import com.pageselect.entity.HjyCommunity;
import com.pageselect.page.PageResult;
import com.pageselect.service.HjyCommunityService;
import com.pageselect.utils.ServletUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/community")
public class HjyCommunityController {

    @Resource
    private HjyCommunityService hjyCommunityService;

    /**
     * 查询小区
     *
     * @param hjyCommunity
     * @return: com.msb.hjycommunity.common.core.page.PageResult
     */
    @GetMapping("/list")
    public PageResult list(HjyCommunity hjyCommunity) {
        Integer pageSize = ServletUtils.getParameterToInt("pageSize");
        Integer pageNum = ServletUtils.getParameterToInt("pageNum");

        PageHelper.startPage(pageNum, pageSize);

        List<HjyCommunityDto> result = hjyCommunityService.queryList(hjyCommunity);
        PageInfo<HjyCommunityDto> pageInfo = new PageInfo<>(result);

        //封装数据
        PageResult pageResult = new PageResult();
        pageResult.setCode(HttpStatus.SUCCESS);
        pageResult.setMsg("查询成功");
        pageResult.setRows(result);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }


}